unit ODBCINST;

interface

uses
  Windows;

type
  SQLRETURN = integer;
  UWORD     = Word;


{ SQLConfigDataSource request flags }
const
  ODBC_ADD_DSN = 1;    { Add data source}
  ODBC_CONFIG_DSN = 2; { Configure (edit) data source}
  ODBC_REMOVE_DSN = 3; { Remove data source}

const
  ODBC_ADD_SYS_DSN = 4;          { add a system DSN}
  ODBC_CONFIG_SYS_DSN = 5;       { Configure a system DSN}
  ODBC_REMOVE_SYS_DSN = 6;       { remove a system DSN}
  ODBC_REMOVE_DEFAULT_DSN = 7;   { remove the default DSN}

{ install request flags }
const
  ODBC_INSTALL_INQUIRY = 1;
  ODBC_INSTALL_COMPLETE = 2;

{ config driver flags }
const
  ODBC_INSTALL_DRIVER = 1;
  ODBC_REMOVE_DRIVER = 2;
  ODBC_CONFIG_DRIVER = 3;
  ODBC_CONFIG_DRIVER_MAX = 100;

{ SQLGetConfigMode and SQLSetConfigMode flags }
const
  ODBC_BOTH_DSN = 0;
  ODBC_USER_DSN = 1;
  ODBC_SYSTEM_DSN = 2;

{ SQLInstallerError code }
const
  ODBC_ERROR_GENERAL_ERR = 1;
  ODBC_ERROR_INVALID_BUFF_LEN = 2;
  ODBC_ERROR_INVALID_HWND = 3;
  ODBC_ERROR_INVALID_STR = 4;
  ODBC_ERROR_INVALID_REQUEST_TYPE = 5;
  ODBC_ERROR_COMPONENT_NOT_FOUND = 6;
  ODBC_ERROR_INVALID_NAME = 7;
  ODBC_ERROR_INVALID_KEYWORD_VALUE = 8;
  ODBC_ERROR_INVALID_DSN = 9;
  ODBC_ERROR_INVALID_INF = 10;
  ODBC_ERROR_REQUEST_FAILED = 11;
  ODBC_ERROR_INVALID_PATH = 12;
  ODBC_ERROR_LOAD_LIB_FAILED = 13;
  ODBC_ERROR_INVALID_PARAM_SEQUENCE = 14;
  ODBC_ERROR_INVALID_LOG_FILE = 15;
  ODBC_ERROR_USER_CANCELED = 16;
  ODBC_ERROR_USAGE_UPDATE_FAILED = 17;
  ODBC_ERROR_CREATE_DSN_FAILED = 18;
  ODBC_ERROR_WRITING_SYSINFO_FAILED = 19;
  ODBC_ERROR_REMOVE_DSN_FAILED = 20;
  ODBC_ERROR_OUT_OF_MEM = 21;
  ODBC_ERROR_OUTPUT_STRING_TRUNCATED = 22;


{-------------------- function headers ------------------------ }

{ High level APIs }

function SQLInstallODBC(hwndParent: HWND;
  lpszInfFile: PChar;
  lpszSrcPath: PChar;
  lpszDrivers: PChar): BOOL stdcall;

function SQLManageDataSources(hwndParent: HWND): BOOL stdcall;

function SQLCreateDataSource(hwndParent: HWND; lpszDSN: PChar): BOOL stdcall;

function SQLGetTranslator(hwnd: HWND;
  lpszName: PChar;
  cbNameMax: Word;
  var pcbNameOut: Word;
  lpszPath: PChar;
  cbPathMax: Word;
  var pcbPathOut: Word;
  var pvOption: LongInt): BOOL stdcall;

{ Low level APIs }
{NOTE: The high-level APIs should always be used. These APIs }
{have been left for compatibility. }

function SQLInstallDriver(lpszInfFile: PChar;
  lpszDriver: PChar;
  lpszPath: PChar;
  cbPathMax: Word;
  var pcbPathOut: Word): BOOL stdcall;

function SQLInstallDriverManager(lpszPath: PChar;
  cbPathMax: Word;
  var pcbPathOut: Word): BOOL stdcall;

function SQLGetInstalledDrivers(lpszBuf: PChar;
  cbBufMax: Word;
  var pcbBufOut: Word): BOOL stdcall;

function SQLGetAvailableDrivers(lpszInfFile: PChar;
  lpszBuf: PChar;
  cbBufMax: Word;
  var pcbBufOut: Word): BOOL stdcall;

function SQLConfigDataSource(hwndParent: HWND;
  fRequest: Word;
  lpszDriver: PChar;
  lpszAttributes: PChar ): BOOL stdcall;


function SQLRemoveDefaultDataSource: BOOL stdcall;

function SQLWriteDSNToIni(lpszDSN: PChar;
  lpszDriver: PChar): BOOL stdcall;

function SQLRemoveDSNFromIni(lpszDSN: PChar): BOOL stdcall;

function SQLValidDSN(lpszDSN: PChar): BOOL stdcall;


function SQLWritePrivateProfileString(lpszSection: PChar;
  lpszEntry: PChar;
  lpszString: PChar;
  lpszFilename: PChar): BOOL stdcall;


function SQLGetPrivateProfileString(lpszSection: PChar;
  lpszEntry: PChar;
  lpszDefault: PChar;
  lpszRetBuffer: PChar;
  cbRetBuffer: Integer;
  lpszFilename: PChar): Integer stdcall;

function SQLRemoveDriverManager(var lpdwUsageCount: LongInt): BOOL stdcall;

function SQLInstallTranslator(lpszInfFile: PChar;
  lpszTranslator: PChar;
  lpszPathIn: PChar;
  lpszPathOut: PChar;
  cbPathOutMax: Word;
  var pcbPathOut: Word;
  fRequest: Word;
  var lpdwUsageCount: LongInt): BOOL stdcall;

function SQLRemoveTranslator(lpszTranslator: PChar;
  var lpdwUsageCount: LongInt): BOOL stdcall;

function SQLRemoveDriver(lpszDriver: PChar;
  fRemoveDSN: BOOL;
  var lpdwUsageCount: LongInt): BOOL stdcall;

function SQLConfigDriver(hwndParent: HWND;
  fRequest: Word;
  lpszDriver: PChar;
  lpszArgs: PChar;
  lpszMsg: PChar;
  cbMsgMax: Word;
  var pcbMsgOut: Word): BOOL stdcall;

function SQLInstallerError(iError: Word;
  var pfErrorCode: LongInt;
  lpszErrorMsg: PChar;
  cbErrorMsgMax: Word;
  var pcbErrorMsg: Word): SQLRETURN stdcall;

function SQLPostInstallerError(dwErrorCode: LongInt;
  lpszErrMsg: PChar): SQLRETURN stdcall;


function SQLWriteFileDSN(lpszFileName: PChar;
  lpszAppName: PChar;
  lpszKeyName: PChar;
  lpszString: PChar): BOOL stdcall;


function SQLReadFileDSN(lpszFileName: PChar;
  lpszAppName: PChar;
  lpszKeyName: PChar;
  lpszString: PChar;
  cbString: Word;
  var pcbString: Word): BOOL stdcall;

function SQLInstallDriverEx(lpszDriver: PChar;
  lpszPathIn: PChar;
  lpszPathOut: PChar;
  cbPathOutMax: Word;
  var pcbPathOut: Word;
  fRequest: Word;
  var lpdwUsageCount: LongInt): BOOL stdcall;

function SQLInstallTranslatorEx(lpszTranslator: PChar;
  lpszPathIn: PChar;
  lpszPathOut: PChar;
  cbPathOutMax: Word;
  var pcbPathOut: Word;
  fRequest: Word;
  var lpdwUsageCount: LongInt): BOOL stdcall;

function SQLGetConfigMode(var pwConfigMode: UWORD): BOOL stdcall;

function SQLSetConfigMode(wConfigMode: UWORD): BOOL stdcall;


{ Driver specific Setup APIs called by installer }

function ConfigDSN(hwndParent: HWND;
  fRequest: Word;
  lpszDriver: PChar;
  lpszAttributes: PChar): BOOL stdcall;


function ConfigTranslator(hwndParent: HWND;
  var pvOption: LongInt): BOOL stdcall;


function ConfigDriver(hwndParent: HWND;
  fRequest: Word;
  lpszDriver: PChar;
  lpszArgs: PChar;
  lpszMsg: PChar;
  cbMsgMax: Word;
  var pcbMsgOut: Word): BOOL stdcall;


{ UNICODE APIs }

{ High level APIs }

function SQLInstallODBCW(hwndParent: HWND;
  lpszInfFile: PWideChar;
  lpszSrcPath: PWideChar;
  lpszDrivers: PWideChar): BOOL stdcall;

function SQLCreateDataSourceW(hwndParent: HWND;
  lpszDSN: PWideChar): BOOL stdcall;

function SQLGetTranslatorW(hwnd: HWND;
  lpszName: PWideChar;
  cbNameMax: Word;
  var pcbNameOut: Word;
  lpszPath: PWideChar;
  cbPathMax: Word;
  var pcbPathOut: Word;
  var pvOption: LongInt): BOOL stdcall;

{ Low level APIs }
{ NOTE: The high-level APIs should always be used. These APIs }
{ have been left for compatibility. }

function SQLInstallDriverW(lpszInfFile: PWideChar;
  lpszDriver: PWideChar;
  lpszPath: PWideChar;
  cbPathMax: Word;
  var pcbPathOut: Word): BOOL stdcall;

function SQLInstallDriverManagerW(lpszPath: PWideChar;
  cbPathMax: Word;
  var pcbPathOut: Word): BOOL stdcall;

function SQLGetInstalledDriversW(lpszBuf: PWideChar;
  cbBufMax: Word;
  var pcbBufOut: Word): BOOL stdcall;

function SQLGetAvailableDriversW(lpszInfFile: PWideChar;
  lpszBuf: PWideChar;
  cbBufMax: Word;
  var pcbBufOut: Word): BOOL stdcall;

function SQLConfigDataSourceW(hwndParent: HWND;
  fRequest: Word;
  lpszDriver: PWideChar;
  lpszAttributes: PWideChar): BOOL stdcall;

function SQLWriteDSNToIniW(lpszDSN: PWideChar;
  lpszDriver: PWideChar): BOOL stdcall;

function SQLRemoveDSNFromIniW(lpszDSN: PWideChar): BOOL stdcall;

function SQLValidDSNW(lpszDSN: PWideChar): BOOL stdcall;


function SQLWritePrivateProfileStringW(lpszSection: PWideChar;
  lpszEntry: PWideChar;
  lpszString: PWideChar;
  lpszFilename: PWideChar): BOOL stdcall;


function SQLGetPrivateProfileStringW(lpszSection: PWideChar;
  lpszEntry: PWideChar;
  lpszDefault: PWideChar;
  lpszRetBuffer: PWideChar;
  cbRetBuffer: Integer;
  lpszFilename: PWideChar): Integer stdcall;

function SQLInstallTranslatorW(lpszInfFile: PWideChar;
  lpszTranslator: PWideChar;
  lpszPathIn: PWideChar;
  lpszPathOut: PWideChar;
  cbPathOutMax: Word;
  var pcbPathOut: Word;
  fRequest: Word;
  var lpdwUsageCount: LongInt): BOOL stdcall;

function SQLRemoveTranslatorW(lpszTranslator: PWideChar;
  var lpdwUsageCount: LongInt): BOOL stdcall;

function SQLRemoveDriverW(lpszDriver: PWideChar;
  fRemoveDSN: BOOL;
  var lpdwUsageCount: LongInt): BOOL stdcall;

function SQLConfigDriverW(hwndParent: HWND;
  fRequest: Word;
  lpszDriver: PWideChar;
  lpszArgs: PWideChar;
  lpszMsg: PWideChar;
  cbMsgMax: Word;
  var pcbMsgOut: Word): BOOL stdcall;

function SQLInstallerErrorW(iError: Word;
  var pfErrorCode: LongInt;
  lpszErrorMsg: PWideChar;
  cbErrorMsgMax: Word;
  var pcbErrorMsg: Word): SQLRETURN stdcall;

function SQLPostInstallerErrorW(dwErrorCode: LongInt;
  lpszErrorMsg: PWideChar): SQLRETURN stdcall;


function SQLWriteFileDSNW(var lpszFileName: PWideChar;
  lpszAppName: PWideChar;
  lpszKeyName: PWideChar;
  lpszString: PWideChar): BOOL stdcall;


function SQLReadFileDSNW(lpszFileName: PWideChar;
  lpszAppName: PWideChar;
  lpszKeyName: PWideChar;
  lpszString: PWideChar;
  cbString: Word;
  var pcbString: Word): BOOL stdcall;

function SQLInstallDriverExW( lpszDriver: PWideChar;
  lpszPathIn: PWideChar;
  lpszPathOut: PWideChar;
  cbPathOutMax: Word;
  var pcbPathOut: Word;
  fRequest: Word;
  var lpdwUsageCount: LongInt): BOOL stdcall;

function SQLInstallTranslatorExW(lpszTranslator: PWideChar;
  lpszPathIn: PWideChar;
  lpszPathOut: PWideChar;
  cbPathOutMax: Word;
  var pcbPathOut: Word;
  fRequest: Word;
  var lpdwUsageCount: LongInt): BOOL stdcall;


{ Driver specific Setup APIs called by installer }

function ConfigDSNW(hwndParent: HWND;
  fRequest: Word;
  lpszDriver: PWideChar;
  lpszAttributes: PWideChar): BOOL stdcall;

function ConfigDriverW(hwndParent: HWND;
  fRequest: Word;
  lpszDriver: PWideChar;
  lpszArgs: PWideChar;
  lpszMsg: PWideChar;
  cbMsgMax: Word;
  var pcbMsgOut: Word): BOOL stdcall;


const
  odbccp32  = 'odbccp32.dll';



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//******************************************************************************
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------




implementation


function SQLInstallODBC; external odbccp32;
function SQLManageDataSources; external odbccp32;
function SQLCreateDataSource; external odbccp32;
function SQLGetTranslator; external odbccp32;
function SQLInstallDriver; external odbccp32;
function SQLInstallDriverManager; external odbccp32;
function SQLGetInstalledDrivers; external odbccp32;
function SQLGetAvailableDrivers; external odbccp32;
function SQLConfigDataSource; external odbccp32;
function SQLRemoveDefaultDataSource; external odbccp32;
function SQLWriteDSNToIni; external odbccp32;
function SQLRemoveDSNFromIni; external odbccp32;
function SQLValidDSN; external odbccp32;
function SQLWritePrivateProfileString; external odbccp32;
function SQLGetPrivateProfileString; external odbccp32;
function SQLRemoveDriverManager; external odbccp32;
function SQLInstallTranslator; external odbccp32;
function SQLRemoveTranslator; external odbccp32;
function SQLRemoveDriver; external odbccp32;
function SQLConfigDriver; external odbccp32;
function SQLInstallerError; external odbccp32;
function SQLPostInstallerError; external odbccp32;
function SQLWriteFileDSN; external odbccp32;
function SQLReadFileDSN; external odbccp32;
function SQLInstallDriverEx; external odbccp32;
function SQLInstallTranslatorEx; external odbccp32;
function SQLGetConfigMode; external odbccp32;
function SQLSetConfigMode; external odbccp32;
function ConfigDSN; external odbccp32;
function ConfigTranslator; external odbccp32;
function ConfigDriver; external odbccp32;
function SQLInstallODBCW; external odbccp32;
function SQLCreateDataSourceW; external odbccp32;
function SQLGetTranslatorW; external odbccp32;
function SQLInstallDriverW; external odbccp32;
function SQLInstallDriverManagerW; external odbccp32;
function SQLGetInstalledDriversW; external odbccp32;
function SQLGetAvailableDriversW; external odbccp32;
function SQLConfigDataSourceW; external odbccp32;
function SQLWriteDSNToIniW; external odbccp32;
function SQLRemoveDSNFromIniW; external odbccp32;
function SQLValidDSNW; external odbccp32;
function SQLWritePrivateProfileStringW; external odbccp32;
function SQLGetPrivateProfileStringW; external odbccp32;
function SQLInstallTranslatorW; external odbccp32;
function SQLRemoveTranslatorW; external odbccp32;
function SQLRemoveDriverW; external odbccp32;
function SQLConfigDriverW; external odbccp32;
function SQLInstallerErrorW; external odbccp32;
function SQLPostInstallerErrorW; external odbccp32;
function SQLWriteFileDSNW; external odbccp32;
function SQLReadFileDSNW; external odbccp32;
function SQLInstallDriverExW; external odbccp32;
function SQLInstallTranslatorExW; external odbccp32;
function ConfigDSNW; external odbccp32;
function ConfigDriverW; external odbccp32;


end.

